import pyopencl as cl , numpy     # import PyOpenCL module

a = numpy.random.rand(50000).astype(numpy.float32)  # create a buffer on host

ctx = cl.create_some_context()    # create an OpenCL context
queue = cl.CommandQueue(ctx)

# create a buffer on device and copy the data in host buffer to device buffer
a_buf = cl.Buffer(ctx , cl.mem_flags.READ_WRITE, size=a.nbytes) 
cl.enqueue_write_buffer(queue, a_buf , a)

# specify an OpenCL kernel function
prg = cl.Program(ctx, """   
      __kernel void twice(__global float *a)
      {
          int gid = get_global_id (0);
          a[gid] *= 2;
      }
      """).build()

# run an OpenCL kernel function
prg.twice(queue, a.shape, None, a_buf).wait()
